package common.bean;

import java.io.PrintWriter;
import java.io.StringWriter;

/**
 * 用于返回JSON结果数据的封装
 * 
 * @author liuxj
 * @version 1.0.0 2017-07-15
 */
public class ResultJsonWrap extends ToStringBean {
    private static final long serialVersionUID = -7857956965424828813L;

    /** 是否成功 */
    private boolean flag = true;

    /** 返回的成功或错误的编码 */
    private String code;

    /** 调用接口返回的消息 **/
    private String msg = "调用成功";

    /** 返回的数据对象 */
    private Object data = "{}";
    
    /** 异常堆栈信息 */
    private String exStackTrace;
    
    public void setErrorMsg(String msg) {
        this.flag = false;
        this.msg = msg;
    }
    
    public void setErrorMsg(String msg, Throwable ex) {
        this.flag = false;
        this.msg = msg;
        
        if (ex != null) {
            StringWriter sw = new StringWriter();
            ex.printStackTrace(new PrintWriter(sw));
            
            this.exStackTrace = sw.toString();
        }
    }

    public boolean getFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public String getExStackTrace() {
        return exStackTrace;
    }

    public void setExStackTrace(String exStackTrace) {
        this.exStackTrace = exStackTrace;
    }

}
